package org.bozo.im.service.core.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	public static int DATABASE_VERSION = 1;
	public static String DATABASE_NAME = "bozo_unified_im";
	
	public static String ACCOUNT_TABLE_NAME = "unified_im_accounts";
	public static String CONTACT_TABLE_NAME = "unified_im_contacts_5";

	public static String ACCOUNT_FIELD_ID = "_ID";
	public static String ACCOUNT_FIELD_PROTOCOL = "protocol";
	public static String ACCOUNT_FIELD_LOGIN = "login";
	public static String ACCOUNT_FIELD_PASSWORD = "password";
	public static String ACCOUNT_FIELD_SERVER = "server";
	public static String ACCOUNT_FIELD_PORT = "port";

	public static String CONTACT_FIELD_ID = "_ID";
	public static String CONTACT_FIELD_PROTOCOL = "protocol";
	public static String CONTACT_FIELD_HANDLE = "handle";

	public DatabaseHelper(Context pContext) {
		super(pContext, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase pDatabase) {
		
		StringBuilder lBuilder = new StringBuilder();
		
		lBuilder.append("CREATE TABLE ").append(ACCOUNT_TABLE_NAME).append("(")
			.append(ACCOUNT_FIELD_ID).append(" INTEGER PRIMARY KEY AUTOINCREMENT, ")
			.append(ACCOUNT_FIELD_PROTOCOL).append(" TEXT, ")
			.append(ACCOUNT_FIELD_LOGIN).append(" TEXT, ")
			.append(ACCOUNT_FIELD_PASSWORD).append(" TEXT, ")
			.append(ACCOUNT_FIELD_SERVER).append(" TEXT, ")
			.append(ACCOUNT_FIELD_PORT).append(" INTEGER);");
		
		pDatabase.execSQL(lBuilder.toString());
		
		lBuilder = new StringBuilder();
		
		lBuilder.append("CREATE TABLE ").append(CONTACT_TABLE_NAME).append("(")
			.append(CONTACT_FIELD_ID).append(" INTEGER PRIMARY KEY, ")
			.append(CONTACT_FIELD_PROTOCOL).append(" TEXT, ")
			.append(CONTACT_FIELD_HANDLE).append(" TEXT);");

		pDatabase.execSQL(lBuilder.toString());
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase pDb, int pOldVersion, int pNewVersion) {}
}
